﻿using System;
using System.Collections.Generic;
using System.Text;

namespace SQL_Manager.OTServ
{
    static class Toolbox
    {
        static public Int64 ExperienceForLevel(int Level)
        {
            return (Int64)checked(Math.Ceiling((double)(((50 * Level / 3 - 100) * Level + 850 / 3) * Level - 200)));
        }

        static public Int64 ExperienceForLevel(int Level, Int64 Experience)
        {
            return (Int64)checked(Math.Ceiling((double)(((50 * Level / 3 - 100) * Level + 850 / 3) * Level - 200) - Experience));
        }

        static public int LevelForExperience(Int64 Experience)
        {
            int Level = 1;
            Int64 exp = 0;

            do
            {
                exp = ExperienceForLevel(Level);

                if (Experience >= exp)
                {
                    Experience -= exp;
                    Level++;
                }
                else
                {
                    Experience = 0;
                }
            }
            while (Experience > 0);

            return Level;
        }

        static public int GetBaseSpeed(int Level)
        {
            return 220 + (2 * (Level - 1));
        }

        static public int GetExperienceLoss(int Experience, int Loss_Experience)
        {
            return (int)checked(Math.Ceiling(Experience * ((double)Loss_Experience / 100)));
        }
    }
}
